import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/button_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/my_app_bar.dart';
import 'package:appflutterhomeschool/ui/widgets/widgets.dart';
import 'package:appflutterhomeschool/utils/utils.dart';
import 'package:appflutterhomeschool/view_model/my/new_class_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///用户： ninetailedfox
///时间： 2020/6/29
///邮箱： 1037438704@qq.com
///功能： 新建班级

class NewClassPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Scaffold(
        resizeToAvoidBottomInset: false,
        backgroundColor: Colors.white,
        appBar: MyAppBar2(title: "新建班级"),
        body: ProviderWidget<NewClassViewModel>(
          model: NewClassViewModel(context),
          onModelReady: (value) => value.initView(),
          builder: (context, viewModel, child) {
            return Stack(
              children: [
                Positioned(
                  top: 0,
                  left: 0,
                  right: 0,
                  bottom: ScreenUtil().setWidth(114),
                  child: Column(
                    children: [
                      ReplyTitleWidget(
                        leftTitle: "学校：",
                        textEditingController: viewModel.schoolName,
                      ),
                      ReplyTitleWidget(
                        leftTitle: "年级：",
                        textEditingController: viewModel.gradeName,
                      ),
                      ReplyTitleWidget(
                        leftTitle: "班级：",
                        textEditingController: viewModel.className,
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        margin: EdgeInsets.all(ScreenUtil().setWidth(32)),
                        child: Text(
                          "您教育的目的",
                          style: TextStyles.textDark37,
                        ),
                      ),
                      SizedBox(height: ScreenUtil().setWidth(10)),
                      GridView.builder(
                        shrinkWrap: true,
                        itemCount: viewModel.gridList.length,
                        physics: NeverScrollableScrollPhysics(),
                        padding: EdgeInsets.symmetric(horizontal: 16),
                        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                          crossAxisCount: 5,
                          mainAxisSpacing: 5,
                          crossAxisSpacing: 5,
                          childAspectRatio: 1,
                        ),
                        itemBuilder: (context, index) {
                          return GestureDetector(
                            onTap: () => viewModel.onTapList(index),
                            child: Column(
                              children: <Widget>[
                                Image.network(
                                  viewModel.gridList[index].judge
                                      ? viewModel.gridList[index].imageUrl
                                      : viewModel.gridList[index].imageUrlFalse,
                                  width: ScreenUtil().setWidth(97),
                                  height: ScreenUtil().setWidth(97),
                                ),
                                Text(viewModel.gridList[index].title ?? "",
                                    style: TextStyles.textDark28)
                              ],
                            ),
                          );
                        },
                      ),
                    ],
                  ),
                ),
                Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: ButtonWidget().rectangleButtonWidget(
                      buttonName: "新建", onPressed: viewModel.newOnTap),
                ),
              ],
            );
          },
        ),
      ),
      onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
    );
  }
}
